class Bird extends Animal {
    {
        name = "小花";
        weight = 15;
    }

    @Override
    protected void action() {
        System.out.println(name + "正在天空翱翔");
    }
}

class Fish extends Animal{
    {
        name = "大黑";
        weight = 50;
    }

    @Override
    protected void action() {
        System.out.println(name + "正在东海游泳");
    }
}

public class Test{
    //2.方法传参：形参为父类型引用，可以接收任意子类的对象
    public static void actionAnimal(Animal animal){
        animal.action();
    }

    //3.作返回值：返回任意子类对象
    public static  Animal buyAnimal(String var){
        if(var == "鸟"){
            return new Bird();
        }else if(var == "鱼"){
            return new Fish();
        }else{
            return null;
        }
    }

    public static void main(String[] args) {
        //1.直接赋值：子类对象赋值给父类对象
        Animal bird = new Bird();
        Fish fish = new Fish();
        actionAnimal(bird);
        actionAnimal(fish);
        Animal animal = buyAnimal("鸟");
        animal.action();
        animal = buyAnimal("鱼");
        animal.action();
    }
}